home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Phreaking⁄Wardialers / Phreaking texts / UseANSI.txt < prev    next >
Text File  |  1999-01-28  |  16KB  |  436 lines

  1. üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü
  2.                             USING THE ANSI DRIVER
  3.  
  4.                                       by
  5.  
  6.                                 C. Scot Giles
  7.                                875 Lake Street
  8.                           Oak Park, Illinois   60301
  9.  
  10.  
  11. This essay is an attempt to explain how I use the ANSI.SYS driver to configure
  12. the function keys on my computer, and to control the screen.  I have used
  13. these techniques on my PC and AT for years, and find them to be convenient and
  14. effective.  ANSI is not widely used by microcomputer fans because the
  15. documentation supplied by IBM on how to send control codes to the ANSI driver
  16. is among the most cryptic ever produced by IBM.  I learned them by reading
  17. computer magazines, and slowly figured out how it could be done.  I am not a
  18. professional computer programmer (indeed I am a clergyman), so some of my
  19. technical observations might be in error.  But everything here works, and I
  20. have retested it before finishing this essay.
  21.  
  22. This essay covers only IBM Personal Computers (PC, XT or AT) running DOS 2.n
  23. or greater.  I have no experience with compatibles, so you are on your own if
  24. you try to use these techniques on one.
  25.  
  26.                            LOADING THE ANSI DRIVER
  27.  
  28. In order to use any of the techniques in this essay, you must first have
  29. loaded the ANSI.SYS driver into your computer's memory using your CONFIG.SYS
  30. file.  You do this my adding the line, DEVICE=ANSI.SYS somewhere in the
  31. CONFIG.SYS file and rebooting your computer.
  32.  
  33.  
  34.  
  35.                        KEYBOARD REASSIGNMENT WITH ANSI
  36.  
  37.  
  38. Before we get to specific ways to send control codes to the (now loaded) ANSI
  39. driver, you must first know what those codes mean.  For the function keys the
  40. codes are listed on the chart below which first appeared in SOFTALK magazine.
  41. Each function key is assigned an "extended function code" which DOS will use
  42. to recognize that a function key has been pressed and in what shifted mode, if
  43. any.  Each number is expressed as a 0 followed by a semi-colon, then the
  44. number from the chart below.
  45.  
  46.                 KEY     NORMAL  SHIFT   CONTROL  ALT
  47.                 F1      59      84      94      104
  48.                 F2      60      85      95      105
  49.                 F3      61      86      96      106
  50.                 F4      62      87      97      107
  51.                 F5      63      88      98      108
  52.                 F6      64      89      99      109
  53.                 F7      65      90      100     110
  54.                 F8      66      91      101     111
  55.                 F9      67      92      102     112
  56.                 F10     68      93      103     113
  57.  
  58. Accordingly, the way to designate the F5 key would be 0;63 while the F10 key
  59. would be designated by 0;68 or 0;113 if shifted with the ALT key.
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü
  69.                        Using the ANSI driver, Page -2-
  70.  
  71.  
  72.  
  73. If you examine the DOS Technical Reference Manual (not the Technical Manual
  74. for PC hardware), you will find a section on SCREEN/KEYS.  This section was
  75. contained in the DOS 2.0 documentation, but IBM removed it in later editions.
  76. Here is a summary of its contents relative to keyboard redefinition.
  77.  
  78. To change one key to have the meaning of another, enter:
  79.  
  80.                                  ESC [#;#p
  81.  
  82. where the first # is the ASCII value of the key being changed and the second #
  83. is the ASCII value of the new definition.  For example, "A" has the ASCII
  84. value of 65 and "Q" has the value of 81.  So:
  85.  
  86.                                  ESC [65;81p
  87.  
  88. will result in "A" being redefined as "Q."  It is also possible to redefine a
  89. key to have the meaning of a string of characters.  This is done by enclosing
  90. the string in quotes.  So:
  91.  
  92.                                  ESC [65;"Hi there"p
  93.  
  94. would change the "A" key to have the meaning of "Hi there."  If the first
  95. value for the first # is a 0 however, DOS knows that what is being changed is
  96. not an ASCII value but the meaning of an extended function code.  So if you
  97. were to enter:
  98.  
  99.                                  ESC [0;68;"Hi there"p
  100.  
  101. DOS would know to change the meaning of the function key (in this case F10) to
  102. the sting enclosed in quotes.  This is the key to redefining your function
  103. keys to perform much used commands: like DIR, CHKDSK, COPY *.* B: etc. or to
  104. load programs from disk.
  105.  
  106. There is a final trick here.  If you end the escape command sequence with the
  107. characters ";13p" instead of just "p" the command will self-execute, just as
  108. if you pressed the [enter] key.
  109.  
  110. The IBM documentation tells the user to preface each command by an ESC
  111. command, and I have represented this in the above paragraphs by writing the
  112. characters "ESC." at the start of each control code sequence mentioned.  Most
  113. users assume that this means to press the ESC key on the keyboard when
  114. entering the commands.  Not so.  To get the Escape Sequence to the ANSI driver
  115. you must enter it using a prompt command or write a .COM file.  For example to
  116. configure the F1 key (extended function code 59) to have the meaning in DOS of
  117. "autoexec" with an [enter] command at the end of it you cannot type:
  118.  
  119.                                 ESC [0;59;"autoexec";13p
  120.  
  121. as the ESC will not be recognized by DOS as an escape sequence.  What DOS will
  122. recognize as an escape sequence is the characters "$e" although this surely
  123. looks strange at first.  Users familiar with the PROMPT command will notice
  124. that the "$" character is what the PROMPT command uses as an escape sequence,
  125. and that is precisely how we will get the redefinition to be recognized by
  126. DOS.  If you enter the following command:
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü
  136.                        Using the ANSI driver, Page -3-
  137.  
  138.  
  139.  
  140.                                 PROMPT $e[0;59;"autoexec";13p
  141.  
  142. you will see that it works perfectly.  You now have the secret to redefining
  143. the function keys in DOS.  Simply write and run a batch file with a list of
  144. PROMPT commands and you will have done it.  One precaution, ECHO must be ON,
  145. otherwise DOS will suppress the PROMPT command and the escape sequences will
  146. not get through.
  147.  
  148. As an example, let's create a batch file called KEYON.BAT that will set F1 as
  149. EDITOR [enter], F2 as PC-FILE [enter], F3 as PC-CALC [enter], F4 as PC-GRAPH
  150. [enter], F5 as PC-TALK [enter], F6 as PC-WRITE [enter], F7 as BASICA [enter],
  151. F8 as DIR without the [enter], F9 to run a batch file called MENUOFF.BAT
  152. [enter] and F10 to run a batch file called MENUON.BAT [enter].  It would be as
  153. follows:
  154.  
  155.                 echo on
  156.                 PROMPT $e[0;59;"EDITOR";13p
  157.                 PROMPT $e[0;60;"PC-FILE";13p
  158.                 PROMPT $e[0;61;"PC-CALC";13p
  159.                 PROMPT $e[0;62;"PC-GRAPH";13p
  160.                 PROMPT $e[0;63;"PC-TALK";13p
  161.                 PROMPT $e[0;64;"PC-WRITE";13p
  162.                 PROMPT $e[0;65;"BASICA";13p
  163.                 PROMPT $e[0;66;"DIR"p
  164.                 PROMPT $e[0;67;"MENUOFF";13p
  165.                 PROMPT $e[0;68;"MENUON";13p
  166.                 prompt
  167.                 cls
  168.  
  169. You would also want to create another file called KEYOFF.BAT which resets the
  170. function key definitions to DOS normal.  The format would be:
  171.  
  172.                 echo on
  173.                 PROMPT $e[0;59;0;59p
  174.                 PROMPT $e[0;60;0;60p
  175.                 PROMPT $e[0;61;0;61p
  176.                 PROMPT $e[0;62;0;62p
  177.                 PROMPT $e[0;63;0;63p
  178.                 PROMPT $e[0;64;0;64p
  179.                 PROMPT $e[0;65;0;65p
  180.                 PROMPT $e[0;66;0;66p
  181.                 PROMPT $e[0;67;0;67p
  182.                 PROMPT $e[0;68;0;68p
  183.                 prompt
  184.                 cls
  185.  
  186. I should mention that the purpose of the final blank PROMPT command in each of
  187. these batch files is to reset the DOS prompt to A> or whatever your default
  188. prompt is.  It serves no redefinition purpose, but does keep the screen
  189. looking clean.
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü
  203.                        Using the ANSI driver, Page -4-
  204.  
  205.  
  206.                      USING DEBUG TO LOAD THE ANSI DRIVER
  207.  
  208. While there is no reason why we could not continue to configure our function
  209. keys by batch files consisting of lists of PROMPT commands, this is a clumsy
  210. way to proceed.  It is easier to use the DEBUG utility supplied with DOS to
  211. create a .COM file that will do the job for us quickly and directly, without
  212. sending any input to screen.  To my knowledge this technique was first
  213. published by Michael J. Grabel in the December 1984 edition of PC WORLD.
  214.  
  215. Place a formatted DOS disk containing the DEBUG utility in the default drive,
  216. and follow the script below.  As you do so hexadecimal numbers will appear on
  217. the left hand side of your screen.  These numbers will vary depending on the
  218. configuration of your system.  For our purposes here I will represent the
  219. numbers in the form xxxx:nnnn.  What you will see on your screen will be
  220. different.
  221.  
  222. A>DEBUG [enter]
  223. -A 100 [enter]
  224. MOV AH,9 [enter]
  225. MOV DX,109 [enter]
  226. INT 21 [enter]
  227. INT 20 [enter]
  228. xxxx:nnnn DB 1B'[0;59;"EDITOR";13p' [enter]
  229. xxxx:nnnn DB 1B'[0;60;"PC-FILE";13p' [enter]
  230. xxxx:nnnn DB 1B'[0;61;"PC-CALC";13p' [enter]
  231. xxxx:nnnn DB 1B'[0;62;"PC-GRAPH";13p' [enter]
  232. xxxx:nnnn DB 1B'[0;63;"PC-TALK";13p' [enter]
  233. xxxx:nnnn DB 1B'[0;64;"PC-WRITE";13p' [enter]
  234. xxxx:nnnn DB 1B'[0;65;"BASICA";13p' [enter]
  235. xxxx:nnnn DB 1B'[0;66;"DIR"p' [enter]
  236. xxxx:nnnn DB 1B'[0;67;"MENUOFF";13p' [enter]
  237. xxxx:nnnn DB 1B'[0;68;"MENUON";13p' [enter]
  238. xxxx:nnnn DB 1B '$' [enter]
  239.  
  240.      As soon as you have entered the previous line, your computer will respond
  241.      with a number in the form of xxxx:nnnn.  Copy down the portion of the
  242.      number that is being represented here as "nnnn" as you will need it
  243.      later.  Once you have copied the number down, press [enter]
  244.  
  245. xxxx:nnnn [enter]
  246. -N KEYON.COM [enter]
  247. -R BX [enter]
  248.  
  249.      When you have entered the command above, your computer will respond with
  250.      the following line and a colon as a prompt.  At this prompt enter 0 and
  251.      press [enter].
  252.  
  253. BX:0000
  254. :0 [enter]
  255. -R CX [enter]
  256.  
  257.      When you enter the R CX command above, the computer will respond with the
  258.      following line and a colon as a prompt.  At this prompt enter the number,
  259.      "nnnn" you copied down above and press [enter].
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269. üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü
  270.                        Using the ANSI driver, Page -5-
  271.  
  272.  
  273. CX 0000
  274. :nnnn [enter]
  275. -W [enter]
  276.  
  277.      The computer will respond with the following.
  278.  
  279. WRITING nnnn bytes
  280. -Q [enter]
  281.  
  282. As soon as you enter the Q command (for Quit) you will be back at the DOS
  283. prompt, and there will be a new file on disk called KEYON.COM.  Simply type it
  284. at the DOS prompt and your function keys will be configured.  It is a good
  285. idea to use this same procedure to write another .COM file called KEYOFF.COM
  286. which will restore the keys to their native DOS definitions.  The procedure
  287. for this is the same as the above, except that the definition section should
  288. be:
  289.  
  290. xxxx:nnnn DB 1B'[0;59;0;59p' [enter]
  291. xxxx:nnnn DB 1B'[0;60;0;60p' [enter]
  292. xxxx:nnnn DB 1B'[0;61;0;61p' [enter]
  293. xxxx:nnnn DB 1B'[0;62;0;62p' [enter]
  294. xxxx:nnnn DB 1B'[0;63;0;63p' [enter]
  295. xxxx:nnnn DB 1B'[0;64;0;64p' [enter]
  296. xxxx:nnnn DB 1B'[0;65;0;65p' [enter]
  297. xxxx:nnnn DB 1B'[0;66;0;66p' [enter]
  298. xxxx:nnnn DB 1B'[0;67;0;67p' [enter]
  299. xxxx:nnnn DB 1B'[0;68;0;68p' [enter]
  300. xxxx:nnnn DB 1B '$' [enter]
  301.  
  302. If you find that KEYON.COM doesn't work correctly, reboot the machine to clear
  303. the definitions and try again.  The most common mistakes are typing errors (I
  304. often enter a colon when I wanted a semi-colon).  Another source of difficulty
  305. will arise if you have another file on disk to start with called KEYON.COM or
  306. KEYOFF.COM.  DEBUG bypasses the normal file allocation of DOS and writes
  307. directly to the disk.  If you have another file on disk with the same name,
  308. DEBUG will overwrite it, but unless the other file was exactly the same size
  309. as the new one or smaller, there may be a piece of the old file left over
  310. attached to the end of the new one.  As a precaution, always erase old
  311. versions of the .COM files, or better yet give each one a unique name and
  312. rename it later using the DOS Rename command.
  313.  
  314.                             SOME ADDITIONAL TRICKS
  315.  
  316.  
  317. Here are some additional control codes for the ANSI driver, summarized from
  318. the IBM material.
  319.  
  320.  
  321. 1. CURSOR POSITIONING
  322.  
  323.      To move the cursor to a specified position: ESC [#;#h where the first #
  324.      is the desired line number and the second the desire column.
  325.  
  326.      To move the cursor up without changing columns: ESC [#a where # specifies
  327.      the number of lines moved.
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü
  337.                        Using the ANSI driver, Page -6-
  338.  
  339.  
  340.  
  341.      To move the cursor to a specified horizontal and vertical position: ESC
  342.      [#;#f where # means first the line number and secondly the column number.
  343.  
  344.      To get a device status report: ESC [6n
  345.  
  346.      To get a cursor position report: ESC [#;#r where the first # specifies
  347.      the current line and the second # specifies the current column
  348.  
  349.      To move the cursor down: ESC [#b where # specifies the number of lines
  350.      moved down.
  351.  
  352.      To move the cursor forward: ESC [#C where # specifies the number of
  353.      columns moved.
  354.  
  355.      To move the cursor backward: ESC [#d where # specifies the number of
  356.      columns moved.
  357.  
  358.      To save the cursor position: ESC [s and to restore it: ESC [u.
  359.  
  360. 2. ERASING
  361.  
  362.      To do a CLS (erase screen move cursor to home position): ESC [2j
  363.  
  364.      To erase from cursor to end of line: ESC [k
  365.  
  366.  
  367. 3. COLOR GRAPHICS
  368.  
  369.      To set the color/graphics attributes, enter ESC [#;#m where the first #
  370.      is the desired foreground color and the second is the desired background
  371.      color.  Select colors from the list below:
  372.  
  373.      30  black foreground
  374.      31  red foreground
  375.      32  green foreground
  376.      33  yellow foreground
  377.      34  blue foreground
  378.      35  magenta foreground
  379.      36  cyan foreground
  380.      37  white foreground
  381.  
  382.      40  black background
  383.      41  red background
  384.      42  green background
  385.      43  yellow background
  386.      44  blue background
  387.      45  magenta background
  388.      46  cyan background
  389.      47  white background
  390.  
  391.      To set additional attributes enter: ESC [#m where # is the number of the
  392.      desired attribute.  Select attributes from the list below:
  393.  
  394.      0  all attributes off (white on black)
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403. üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü
  404.                        Using the ANSI driver, Page -7-
  405.  
  406.  
  407.      1  bold on
  408.      4  underscore (on IBM Monochrome Display)
  409.      5  blink
  410.      7  reverse video
  411.      8  invisible
  412.  
  413. To give an example of what can be done with these additional codes, a batch
  414. file called MENUOFF.BAT containing only the line:
  415.  
  416.                         PROMPT $e[2J$e[30;40m$h
  417.  
  418. would blank a color display completely.  It does a CLS, sets the display to a
  419. black foreground and background and the with the "$h" performs a backspace to
  420. erase the blinking cursor (the "$h command is documented in the DOS manual
  421. under PROMPT).  Another batch file called MENUON.BAT containing the lines:
  422.  
  423.       PROMPT $e[0m
  424.       prompt
  425.       cls
  426.  
  427. Would reset a color display to restore the screen after MENUOFF.BAT had been
  428. run.
  429.  
  430. Enjoy ANSI!  It is a wonderful tool, and can be a lot of fun to use.  It's not
  431. a keyboard enhancer, and if you load it up with too many keyboard
  432. redefinitions at one time you will run out of environment space.  This is
  433. harmless and simply means that ANSI is full.  But it will work fine to define
  434. your function keys and control your screen.
  435.  
  436.